package com.jinghong.epidemiccontrolproject.controller;
import com.jinghong.epidemiccontrolproject.pojo.PageBean;
import com.jinghong.epidemiccontrolproject.pojo.Patient;
import com.jinghong.epidemiccontrolproject.pojo.Result;
import com.jinghong.epidemiccontrolproject.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;

/**
 * ClassName:PatientController
 * Package:com.jinghong.epidemiccontrolproject.controller
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/1/19 22:41
 * Version:1.0
 */
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name, Short gender, Integer age1, Integer age2, Integer regionId, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end, Short status){
        log.info("分页查询,查询病患信息 参数: {},{},{}",page,pageSize,name);
        //调用service分页查询
        PageBean pageBean = patientService.page(page,pageSize,name,gender,age1,age2,regionId,begin,end,status);
        return Result.success(pageBean);
    }


    @DeleteMapping
    public Result delete( Integer id){
        log.info("删除病患信息 id:{}",id);
        patientService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result save(@RequestBody Patient patient){
        log.info("添加病患信息, emp: {}", patient);
        patientService.save(patient);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据ID查询回显病患信息, id: {}",id);
        Patient Patient = patientService.getById(id);
        return Result.success(Patient);
    }

    @PutMapping
    public Result update(@RequestBody Patient patient){
        log.info("修改病患信息 : {}", patient);
        patientService.update(patient);
        return Result.success();
    }


}
